package com.example.aircraftticketingsystemserver.controller;

import com.example.aircraftticketingsystemserver.entity.Timezone;
import com.example.aircraftticketingsystemserver.mapper.TimezoneMapper;
import com.example.aircraftticketingsystemserver.service.ITimezoneService;
import com.example.aircraftticketingsystemserver.utils.Page;
import com.example.aircraftticketingsystemserver.utils.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = {"*","null"})
@RequestMapping("/timezone")
public class TimezoneController {
    @Resource
    ITimezoneService timezoneService;

    @GetMapping("/getFlightsWithLocalTime")
    public Result getFlightsWithLocalTime(@RequestParam(value = "pageNo") Integer pageNo,
                                          @RequestParam(value = "pageSize") Integer pageSize){
        Page flightsWithLocalTime = timezoneService.getFlightsWithLocalTime(pageNo, pageSize);
        System.out.println("Controller"+flightsWithLocalTime);
        return Result.ok(flightsWithLocalTime);
    }
    /**
     * 添加城市
     */
    @PostMapping("/addCity")
    public  Result addCity(@RequestBody Timezone timezone){
        timezoneService.addCity(timezone);
        return Result.ok();
    }
    /**
     * 删除单个城市
     */
    @GetMapping("/deleteCity")
    public Result deleteCity(@RequestParam Integer cityId){
        timezoneService.deleteCity(cityId);
        return Result.ok();
    }
    /**
     * 批量删除城市
     */
    @GetMapping("/batchDeleteCity")
    public  Result batchDeleteCity(@RequestBody List<Integer>cityIds){
        timezoneService.batchDeleteCity(cityIds);
        return Result.ok();
    }
    /**
     * 更新城市
     */
    @PostMapping("/updateCity")
    public Result updateCity(@RequestBody Timezone timezone){
        timezoneService.updateCity(timezone);
        return  Result.ok();
    }
    /**
     * 分页查询
     */
    @GetMapping("/getCityPage")
    public Result getCityPage(@RequestParam(value = "pageNo")Integer pageNo,
                              @RequestParam(value = "pageSize")Integer pageSize,
                              String city,
                              String timezoneId){
        return Result.ok(timezoneService.getCityByParams(pageNo, pageSize, city, timezoneId));
    }
    @GetMapping("/getCityList")
    public Result getCityList(String city,String timezoneId){
        return Result.ok(timezoneService.getCityList(city, timezoneId));
    }
}
